package org.ejc.tech.combo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.ResourceBundle;

import org.ejc.api.additionalinfo.AdditionalInfoAPIUtil;
import org.ejc.persist.model.AdditionalInfoTypeDesc;


public class AdditionalInfoTypeHandlerImpl implements IComboHandler {

	static HashMap map=new HashMap();
	
	public Collection getLocalizedCollection(Locale locale) {
		return (Collection) map.get(locale.getLanguage());
	}

	public void setupHandler(Collection locales) {
		for (Iterator iter = locales.iterator(); iter.hasNext();) {
				Collection<AdditionalInfoTypeDesc> newCol = new ArrayList<AdditionalInfoTypeDesc>();
				Locale locale = (Locale) iter.next();
				ResourceBundle resource = ResourceBundle.getBundle(
						"org.ejc.resources.AdditionalInfoType", locale);
				try {
					Collection c = AdditionalInfoAPIUtil.getLocalHome().create().getAdditionalInfoTypes();

					for (Iterator iter1 = c.iterator(); iter1.hasNext();) {
						AdditionalInfoTypeDesc element = (AdditionalInfoTypeDesc) iter1.next();
						String key=element.getAdditionalInfoDesc();
						String localizedName = (String) resource.getObject(key);


						AdditionalInfoTypeDesc addType = new AdditionalInfoTypeDesc();
						addType.setAdditionalInfoTypeDescId(element.getAdditionalInfoTypeDescId());
						addType.setAdditionalInfoDesc(localizedName);
						newCol.add(addType);
					}
				} catch (Exception e) {
					//}log.fatal("Error in setting up country codes!");
				}
				map.put(locale.getLanguage(), newCol);
			}
		}
	}


